﻿package game.breeze.message;

import game.breeze.socket.util.ByteBuffer;

/**
 * AppMessage 应用程序消息
 */
public class AppMessage extends Message {
	public static final int MESSAGE_TYPE_NULL = 0;

	public static final AppMessage NULL_MESSAGE = new AppMessage(MESSAGE_TYPE_NULL, new ByteBuffer(0), null);

	/** 场景相关 */
	public static final int MSG_SCENE = 0x100;

	/** 玩家相关 */
	public static final int MSG_PLAYER = 0x200;

	/** 聊天相关 */
	public static final int MSG_CHAT = 0x300;

	/** 战役相关 */
	public static final int MSG_CAMPAIGN = 0x390;

	/** 战斗相关 */
	public static final int MSG_FIGHT = 0x400;

	/** 世界相关 */
	public static final int MSG_WORLD = 0x500;

	/** NPC相关 */
	public static final int MSG_NPC = 0x600;

	/** 商店相关 */
	public static final int MSG_SHOP = 0x700;

	/** 交易相关 */
	public static final int MSG_TRADE = 0x800;

	/** 组队相关 */
	public static final int MSG_TEAM = 0x900;

	/** 任务相关 */
	public static final int MSG_TASK = 0xA00;

	/** 系统相关 */
	public static final int MSG_SYSTEM = 0xB00;

	/** 验证相关 */
	public static final int MSG_AUTH = 0xC00;

	/** 社交社会 */
	public static final int MSG_SNS = 0xD00;

	/** 宠物相关 */
	public static final int MSG_PET = 0xE00;

	private int type;

	public static final AppMessage createMessage(int type) {
		return new AppMessage(type);
	}

	public static final AppMessage createMessage(int type, int size) {
		return new AppMessage(type, size);
	}

	public static final AppMessage createMessage(int type, ByteBuffer buffer) {
		return new AppMessage(type, buffer);
	}

	public static final AppMessage createMessage(int type, ByteBuffer buffer, Object source) {
		return new AppMessage(type, buffer, source);
	}

	private AppMessage(int type) {
		this(type, 256);
	}

	private AppMessage(int type, int size) {
		this(type, new ByteBuffer(size), null);
	}

	private AppMessage(int type, ByteBuffer buffer) {
		this(type, buffer, null);
	}

	private AppMessage(int type, ByteBuffer buffer, Object source) {
		super(buffer, source);
		this.type = type;
	}

	public int getType() {
		return type;
	}

	public ByteBuffer getBuffer() {
		return (ByteBuffer) getContent();
	}

	public String toString() {
		return getClass().getName() + ":" + type + ";" + getBuffer().capacity();
	}
}